package com.syp.auth.dao.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.syp.auth.dao.po.RoleResourceEntity;

@Repository
public interface RoleResourceRepository extends JpaRepository<RoleResourceEntity, Long>, JpaSpecificationExecutor<Long> {

	/**
	 * 根据角色ID删除
	 * 
	 * @param roleId
	 * @return
	 */
	@Query("DELETE RoleResourceEntity WHERE roleId=:roleId")
	@Modifying
	public Integer deleteByRoleId(@Param("roleId") Long roleId);

	/**
	 * 根据角色ID删除,限制在我拥有的资源列表内
	 * 
	 * @param roleId
	 * @return
	 */
	@Query("DELETE RoleResourceEntity WHERE roleId=:roleId AND resId in(:resIdList)")
	@Modifying
	public Integer deleteByRoleIdLimitedInMyDomain(@Param("roleId") Long roleId, @Param("resIdList") List<Long> resIdList);

	/**
	 * 根据资源ID删除
	 * 
	 * @param resId
	 * @return
	 */
	@Query("DELETE RoleResourceEntity WHERE resId=:resId")
	@Modifying
	public Integer deleteByResId(@Param("resId") Long resId);

	/**
	 * 根据角色ID查询
	 * 
	 * @param roleId
	 * @return
	 */
	public List<RoleResourceEntity> getByRoleId(@Param("roleId") Long roleId);

	/**
	 * 根据角色ID列表查询
	 * 
	 * @param roleId
	 * @return
	 */
	@Query("FROM RoleResourceEntity WHERE roleId in(:roleIdList)")
	public List<RoleResourceEntity> getByRoleIdList(@Param("roleIdList") List<Long> roleIdList);
}